<?php
	session_start();
	if ($_GET['gagal'] == 1){
           ?>
            <script type="text/javascript">alert("Operation failed");</script>
           <?
   	}
	if (!isset($_SESSION['Username']) || !isset($_SESSION['Password'])){
        header('Location: index.php');
    }
	require 'database/profile_handler.php';
	require 'database/photo_handler.php';
	require 'database/photo_uploader.php';	
	$u = $_SESSION['Username'];
	$pf = new profile_handler();
	$pf->get_nama_lengkap($u);
	$nama_user = $pf->result[0];
	
	if (isset($_POST['UploadButton'])) {
		$photo_upload = new photo_uploader();
		if ($_POST['mybox']==1) {
			$cek_comment=1;	
		} else {
			$cek_comment=0;	
		}

		$photo_id= $photo_upload->upload_photo($u,$_POST['description_text'],$_POST['description_tag'],$_POST['imageDate'],$_POST['description_category'],$_POST['select_menu'],$cek_comment,$_FILES["file"]);
		header("Location: homepage.php?view=2&photo_id=".$photo_id);
		?>
		<script type="text/javascript">
			alert("Upload is Successfull");
        </script>
        <?php 
	}
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>Uploader</title>
	<script type="text/javascript" src="script/validator.js"></script>
	<script type="text/javascript" src="script/calendar.js"></script>
	<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
    <link rel="stylesheet" href="style/style.css" />
</head>
<body onLoad="HideCalendar()" >
<div id="fb-root"></div>
	<script>
		 function CekUp(Masukan,Photo,Deskripsi,Tag,Tanggal,Kategori,aa,bb,cc,dd,ee)
		 {
		 if(CekGantiUpload(Photo,Deskripsi,Tag,Tanggal,Kategori,aa,bb,cc,dd,ee) == true) // berhasil registrasi
			{
				if(document.getElementById("UploadFrom").Cek[0].checked == true)
				{
				 //tampilkan wallpost
				 FB.init({ 
					appId:'155435634517036', cookie:true, 
					status:true, xfbml:true 
				 });

				 FB.ui({ method: 'feed', 
					message: Masukan});
				}
				return true;
			}
		 return false;
		}
      </script>
    	<div class="group_content" id="title_welcome">
        	 <span id="_title">Hello, <?php echo $nama_user; ?>! Upload Your Best Photo Here! </span>
        </div>
        
        <div class="group_content" id="upload_form">
			 <form id="UploadFrom" method="post" name="uploadphoto" action="uploader.php" enctype="multipart/form-data" onSubmit='return CekUp("Hey... Saya baru upload foto di flickertiew lho :D",ImagesFile.value,description_text.value,description_tag.value,date_input.value,category_input.value,LabelImageSalah,LabelDeskripsiSalah,LabelTagSalah,LabelDateSalah,LabelCategorySalah);'	>
             	<div class="uinputarea">
                    <div class="ulabeler">File Photo</div>
                    <div id="insert_description">
                        <input type="file" id="ImagesFile" name="file" />
						<label class="Peringatan" id="LabelImageSalah"> </label>                        
                    </div>
                </div>
                <div class="uinputarea">
                	<div class="ulabeler">Description</div>
                	<div id="insert_description">
                    	<textarea class="textarea" id="description_text" name="description_text" rows="5" ></textarea>
	                    <label class="Peringatan" id="LabelDeskripsiSalah"> </label>                        
                	</div>           
                </div>
                <div class="uinputarea">
                	<div class="ulabeler">Tag</div>
                	<div id="insert_description">
                    	<textarea class="textarea" id="description_tag" name="description_tag" rows="5" ></textarea>
	                    <label class="Peringatan" id="LabelTagSalah"> </label>                        
                	</div>                    
                </div>
                <div class="uinputarea">
                	<div class="ulabeler">Date Captured</div>
                	<div id="insert_description">
                    	<input type="text" class="textarea" id="date_input" name="imageDate" value="" />
	                    <img alt="" src="script/calendar.jpg" id = "IconCalendar"  onclick = "toggleCalendar('imageDate')" />                    	<label class="Peringatan" id="LabelDateSalah" style="margin-left:50px;"> </label>                     
                        </div>
                    <table border="1" cellpadding="0" cellspacing="3" id="calendar">
                          <tbody>
                          <tr>
                            <td class="today" colspan="5" id="todayday" onClick="">This is calendar popup</td>
                            <td align="right" colspan="2"><a href="javascript:HideCalendar();"><b>Hide</b></a></td>
                          </tr>
                          <tr>
                            <td colspan="7" valign="middle">
                            <!-- Month combo box -->
                            <select id="month" onChange="newCalendar()">
                                <option value="Januari">January</option>
                                <option value="Februari">February</option>
                                <option value="Maret">March</option>
                                <option value="April">April</option>
                                <option value="Mei">May</option>
                                <option value="Juni">June</option>
                                <option value="Juli">July</option>
                                <option value="Agustus">August</option>
                                <option value="September">September</option>
                                <option value="Oktober">October</option>
                                <option value="November">November</option>
                                <option value="Desember">December</option>
                            </select>
                            <!-- Year combo box -->
                            <select id="year" onChange="newCalendar()">
                                <option value="1951">1951</option>
                                <option value="1952">1952</option>
                                <option value="1953">1953</option>
                                <option value="1954">1954</option>
                                <option value="1955">1955</option>
                                <option value="1956">1956</option>
                                <option value="1957">1957</option>
                                <option value="1958">1958</option>
                                <option value="1959">1959</option>
                                <option value="1950">1960</option>
            
                                <option value="1961">1961</option>
                                <option value="1962">1962</option>
                                <option value="1963">1963</option>
                                <option value="1964">1964</option>
                                <option value="1965">1965</option>
                                <option value="1966">1966</option>
                                <option value="1967">1967</option>
                                <option value="1968">1968</option>
                                <option value="1969">1969</option>
                                <option value="1970">1970</option>
            
                                <option value="1971">1971</option>
                                <option value="1972">1972</option>
                                <option value="1973">1973</option>
                                <option value="1974">1974</option>
                                <option value="1975">1975</option>
                                <option value="1976">1976</option>
                                <option value="1977">1977</option>
                                <option value="1978">1978</option>
                                <option value="1979">1979</option>
                                <option value="1980">1980</option>
            
                                <option value="1981">1981</option>
                                <option value="1982">1982</option>
                                <option value="1983">1983</option>
                                <option value="1984">1984</option>
                                <option value="1985">1985</option>
                                <option value="1986">1986</option>
                                <option value="1987">1987</option>
                                <option value="1988">1988</option>
                                <option value="1989">1989</option>
                                <option value="1990">1990</option>
            
                                <option value="1991">1991</option>
                                <option value="1992">1992</option>
                                <option value="1993">1993</option>
                                <option value="1994">1994</option>
                                <option value="1995">1995</option>
                                <option value="1996">1996</option>
                                <option value="1997">1997</option>
                                <option value="1998">1998</option>
                                <option value="1999">1999</option>
                                <option value="2000">2000</option>
            
                                <option value="2001">2001</option>
                                <option value="2002">2002</option>
                                <option value="2003">2003</option>
                                <option value="2004">2004</option>
                                <option value="2005">2005</option>
                                <option value="2006">2006</option>
                                <option value="2007">2007</option>
                                <option value="2008">2008</option>
                                <option value="2009">2009</option>
                                <option value="2010">2010</option>
                                <option value="2011">2011</option>
                            </select>
            
                            </td>
                          </tr>
                          <tr class="days">
                            <!-- Generate column for each day. -->
                            <td>Sunday</td>
                            <td>Monday</td>
                            <td>Tuesday</td>
                            <td>Wednesday</td>
                            <td>Thursday</td>
                            <td>Friday</td>
                            <td>Saturday</td>
                          </tr>
                          </tbody>
            
                          <!-- Generate today day. -->
                          <tbody class="dates" id="dayList" onClick="getDate('')" valign="middle">
                          <!-- Generate grid for individual days. -->
                          <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
                          <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
                          <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
                          <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
                          <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
                          <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
                            </tbody>
            
                        </table>
                </div>
                <div class="uinputarea">
                	<div class="ulabeler">Category</div>
                	<div id="insert_description">
                    	<input type="text" class="textarea" id="category_input" name="description_category" value="" />
                	</div>
                    <label class="Peringatan" id="LabelCategorySalah"> </label>                    
                </div>
                <div class="uinputarea">
                	<div class="ulabeler">Privacy</div>
                    <div id="select_menu">
                        <select name="select_menu" id="select_menu">
                          <option value="everyone">everyone</option>
                          <option value="members only">members only</option>
                          <option value="just followers">just followers</option>                          
                          <option value="only me">only me</option>
                        </select>
                    </div>
                </div>
                <div class="uinputarea">
                	<div class="ulabeler">Allow Comment</div>
                    <div id="select_menu" name="comment_p">
                    	<input type="checkbox" id="mybox" name="mybox" value="1" selected>
                    </div>
                </div> 
				<div class="ulabeler2" id="LabelCek">Ingin ditampilkan di Facebook?</div><input type="radio" id="Cek" name="Cek" value="ya" checked="checked"/> <label> Ya </label> <input type="radio" id="Cek" name="Cek" value="tidak"/> <label> Tidak </label>
				<br />
                <input type="submit" id="SubmitUpload"  name="UploadButton" value="Submit"/>
                <label class="Success" id="LabelSuccessfull"></label>
             </form>

        </div>
        
</body>
</html>